package com.woniu.springboot.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 扩展拦截器
 *      这里写好在config里面进行配置
 */
public class PermissionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

        Object userInfo = request.getSession().getAttribute("userInfo");
        if (userInfo != null){
            return true;
        }else {
            request.setAttribute("errorInfo","请先登录！！！");
            request.getRequestDispatcher("login.html").forward(request,response);
            return false;
        }

    }
}
